package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.WhiteCall;
import com.camps.sdk.entity.WhiteCallReply;
import com.camps.sdk.utils.LocationUtils;
import com.camps.sdk.utils.UnicodeUtil;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeWhiteCall implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,PBWL,095819,1,12487541256,1,0,\u0074\u0065\u0073\u0074,1,095821,A,2250.2256,N,11391.6190,E,0.18,162,030621,FFFFDFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[3];
        Integer sequence = Integer.parseInt(split[4]);
        String phone = split[5];
        String type = split[6];
        String name = split[8];
        String wlMeid = split[7];
        String picId = split[9];
        String time = split[10];//时分秒
        String lat = split[12];
        String lng = split[14];
        String speed = split[16];
        String orientation = split[17];
        String date = split[18];//日月年
        String deviceStatus = split[19];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        WhiteCallReply whiteCallReply = new WhiteCallReply();
        whiteCallReply.setCommandNumber(commandNumber);
        whiteCallReply.setImei(imei);
        whiteCallReply.setDeviceDate(date);
        whiteCallReply.setDeviceTime(time);
        whiteCallReply.setSequence(sequence);
        whiteCallReply.setName(name!=null && !"".equals(name) ? "" : UnicodeUtil.decodeUnicode(name));
        whiteCallReply.setPhone(phone);
        whiteCallReply.setPictureId(Integer.parseInt(picId));
        whiteCallReply.setDeviceDate(deviceStatus);
        whiteCallReply.setType(Integer.parseInt(type));
        LocationData locationData = new LocationData();
        locationData.setOrientation(Integer.parseInt(orientation));
        locationData.setSpeed(Double.parseDouble(speed));
        locationData.setLatitude(list.get(1));
        locationData.setLongitude(list.get(0));
        whiteCallReply.setLocationData(locationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_WHITE_CALL,false,"",whiteCallReply);
    }
}
